package com.haixiaoke.saas.repository.service.impl;

import cn.hutool.core.convert.Convert;
import com.haixiaoke.saas.repository.mapper.HouseFacilitiesMapper;
import com.haixiaoke.saas.repository.pojo.HouseFacilities;
import com.haixiaoke.saas.repository.service.IHouseFacilitiesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 房屋设施Service业务层处理
 *
 * @author qixi
 * @date 2023-04-06
 */
@Service
public class HouseFacilitiesServiceImpl implements IHouseFacilitiesService {
    @Autowired
    private HouseFacilitiesMapper houseFacilitiesMapper;

    /**
     * 查询房屋设施
     *
     * @param facilitiesId 房屋设施主键
     * @return 房屋设施
     */
    @Override
    public HouseFacilities selectHouseFacilitiesByFacilitiesId(Long facilitiesId) {
        return houseFacilitiesMapper.selectHouseFacilitiesByFacilitiesId(facilitiesId);
    }

    @Override
    public List<HouseFacilities> selectHouseFacilitiesByFacilitiesIdIn(List<Long> facilitiesId) {
        return houseFacilitiesMapper.selectHouseFacilitiesByFacilitiesIdIn(facilitiesId);
    }

    /**
     * 查询房屋设施列表
     *
     * @param houseFacilities 房屋设施
     * @return 房屋设施
     */
    @Override
    public List<HouseFacilities> selectHouseFacilitiesList(HouseFacilities houseFacilities) {
        return houseFacilitiesMapper.selectHouseFacilitiesList(houseFacilities);
    }

    /**
     * 新增房屋设施
     *
     * @param houseFacilities 房屋设施
     * @return 结果
     */
    @Override
    public int insertHouseFacilities(HouseFacilities houseFacilities) {
        houseFacilities.setCreateTime(new Date());
        return houseFacilitiesMapper.insertHouseFacilities(houseFacilities);
    }

    /**
     * 修改房屋设施
     *
     * @param houseFacilities 房屋设施
     * @return 结果
     */
    @Override
    public int updateHouseFacilities(HouseFacilities houseFacilities) {
        houseFacilities.setUpdateTime(new Date());
        return houseFacilitiesMapper.updateHouseFacilities(houseFacilities);
    }

    /**
     * 批量删除房屋设施
     *
     * @param facilitiesIds 需要删除的房屋设施主键
     * @return 结果
     */
    @Override
    public int deleteHouseFacilitiesByFacilitiesIds(Long[] facilitiesIds) {
        return houseFacilitiesMapper.deleteHouseFacilitiesByFacilitiesIds(facilitiesIds);
    }

    /**
     * 删除房屋设施信息
     *
     * @param facilitiesId 房屋设施主键
     * @return 结果
     */
    @Override
    public int deleteHouseFacilitiesByFacilitiesId(Long facilitiesId) {
        return houseFacilitiesMapper.deleteHouseFacilitiesByFacilitiesId(facilitiesId);
    }

    /**
     * 校验名称是否重复
     *
     * @param facilitiesName 房屋设施名称
     * @return 结果
     */
    @Override
    public boolean checkFacilitiesNameUnique(String facilitiesName) {
         return houseFacilitiesMapper.checkFacilitiesNameUnique(facilitiesName) == 0;
    }
}
